#
# .zd1211 - USB2.0 802.11b/g driver for Zydas ZD1211 chipsets
#
#
#

HOST=
CC=$(HOST)gcc
LD=$(HOST)ld
KERN_VER=$(shell uname -r | cut -b1-3;)
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

SUBDIRS=.
include .config
include $(SUBDIRS)/.config

ifeq ($(KERN_VER), 2.6) 
    KERN_26=y
    KERNEL_SOURCE=/usr/src/linux-2.6.9
else 
    KERN_24=y
    KERNEL_SOURCE=/usr/src/linux-2.4
endif

SRC_DIR=src
DEFINES=-D__KERNEL__ -DMODULE=1


KERNRELEASE := $(shell uname -r;)
MODPATH := /lib/modules/$(KERNRELEASE)






INCLUDES=-I$(KERNEL_SOURCE)/include -I$(SRC_DIR)/include/ -I$(SRC_DIR)


ifndef CONFIG_FRAME_POINTER
EXTRA_CFLAGS += -fomit-frame-pointer
endif
         
ifdef CONFIG_SMP
EXTRA_CFLAGS += -D__SMP__ -DSMP
endif




EXTRA_CFLAGS += -O2 -Wall -Wstrict-prototypes -pipe -Wno-unused
#EXTRA_CFLAGS += -Wa,-a,-ad -g
EXTRA_CFLAGS += -DZDCONF_WE_STAT_SUPPORT=1
EXTRA_CFLAGS += -DHOST_IF_USB
EXTRA_CFLAGS += -DAMAC
EXTRA_CFLAGS += -DGCCK
EXTRA_CFLAGS += -DOFDM
EXTRA_CFLAGS += -DHOSTAPD_SUPPORT
EXTRA_CFLAGS += -DUSE_EP4_SET_REG
EXTRA_CFLAGS += -DDOWNLOADFIRMWARE
EXTRA_CFLAGS += -DfTX_GAIN_OFDM=0
EXTRA_CFLAGS += -DfNEW_CODE_MAP=1
EXTRA_CFLAGS += -DfWRITE_WORD_REG=1
EXTRA_CFLAGS += -DfREAD_MUL_REG=1
EXTRA_CFLAGS += -DENHANCE_RX=1
EXTRA_CFLAGS += -DZDCONF_LP_SUPPORT=0


EXTRA_CFLAGS += -DZDCONF_MENUDBG
EXTRA_CFLAGS += -DZDCONF_APDBG
EXTRA_CFLAGS += -DZDCONF_BANDEDGE_ADJUST
EXTRA_CFLAGS += -DZDCONF_SES_SUPPORT=1
EXTRA_CFLAGS += -DAAAA03_FIX=0

ifeq ($(ZDCONF_WEXT_WPA), y)
EXTRA_CFLAGS += -DZDCONF_WEXT_WPA=1
else
EXTRA_CFLAGS += -DZDCONF_WEXT_WPA=0
endif

ifeq ($(ZDCONF_ANT_DIVERSITY), y)
EXTRA_CFLAGS += -DZDCONF_ANT_DIVERSITY=1
else
EXTRA_CFLAGS += -DZDCONF_ANT_DIVERSITY=0
endif

ifeq ($(ZDCONF_TR_DBG), y)
EXTRA_CFLAGS += -DZDCONF_TR_DBG=1
else
EXTRA_CFLAGS += -DZDCONF_TR_DBG=0
endif

ifeq ($(ZDCONF_FULL_TIM_FIX), y)
EXTRA_CFLAGS += -DZDCONF_FULL_TIM_FIX=1
else
EXTRA_CFLAGS += -DZDCONF_FULL_TIM_FIX=0
endif

ifeq ($(ZDCONF_IWPRIV_CONNECT), y)
EXTRA_CFLAGS += -DZDCONF_IWPRIV_CONNECT=1
else
EXTRA_CFLAGS += -DZDCONF_IWPRIV_CONNECT=0
endif

ifeq ($(ZDCONF_REGION_CONFIG), y)
EXTRA_CFLAGS += -DZDCONF_REGION_CONFIG=1
else
EXTRA_CFLAGS += -DZDCONF_REGION_CONFIG=0
endif

ifeq ($(ZDCONF_MIC_CHECK), y)
EXTRA_CFLAGS += -DZDCONF_MIC_CHECK=1
else
EXTRA_CFLAGS += -DZDCONF_MIC_CHECK=0
endif

ifeq ($(ZDCONF_SETMULTI_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_SETMULTI_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_SETMULTI_SUPPORT=0
endif

ifeq ($(ZDCONF_SETMAC_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_SETMAC_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_SETMAC_SUPPORT=0
endif

ifeq ($(ZDCONF_PSEUDO_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_PSEUDO_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_PSEUDO_SUPPORT=0
endif


ifeq ($(ZDCONF_FULL_IDS), y)
EXTRA_CFLAGS += -DZDCONF_FULL_IDS=1
else
EXTRA_CFLAGS += -DZDCONF_FULL_IDS=0
endif

ifeq ($(ZDCONF_SIGNAL_INFO), y)
EXTRA_CFLAGS += -DZDCONF_SIGNAL_INFO=1
else
EXTRA_CFLAGS += -DZDCONF_SIGNAL_INFO=0
endif

ifeq ($(ZDCONF_STA_PSM), y)
EXTRA_CFLAGS += -DZDCONF_STA_PSM=1
else
EXTRA_CFLAGS += -DZDCONF_STA_PSM=0
endif

ifeq ($(ZDCONF_DBGMSG_NORMAL), y)
EXTRA_CFLAGS += -DZDCONF_DBGMSG_NORMAL=1
else
EXTRA_CFLAGS += -DZDCONF_DBGMSG_NORMAL=0
endif

ifeq ($(ZDCONF_EXTRA_FIX_IPC), y)
EXTRA_CFLAGS += -DZDCONF_EXTRA_FIX_IPC=1
else
EXTRA_CFLAGS += -DZDCONF_EXTRA_FIX_IPC=0
endif

ifeq ($(ZDCONF_ADHOC_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_ADHOC_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_ADHOC_SUPPORT=0
endif

ifeq ($(ZDCONF_AP_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_AP_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_AP_SUPPORT=0
endif

ifeq ($(ZDCONF_WIN_PROD_IFACE), y)
EXTRA_CFLAGS += -DPRODUCTION=1
else
EXTRA_CFLAGS += -DPRODUCTION=0
endif


#### RFMD RF Support ####
ifeq ($(ZDCONF_RF_RFMD_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_RFMD_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_RFMD_SUPPORT=0
endif

#### AR2124 RF Support ####
ifeq ($(ZDCONF_RF_AR2124_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_AR2124_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_AR2124_SUPPORT=0
endif

#### UW2453 RF Support ####
ifeq ($(ZDCONF_RF_UW2453_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_UW2453_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_UW2453_SUPPORT=0
endif

#### AL2232 RF Support ####
ifeq ($(ZDCONF_RF_AL2232_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_AL2232_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_AL2232_SUPPORT=0
endif

#### AL2230(s) RF Support ####
ifeq ($(ZDCONF_RF_AL2230_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_AL2230_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_AL2230_SUPPORT=0
endif

#### AL7230B RF Support ####
ifeq ($(ZDCONF_RF_AL7230B_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_RF_AL7230B_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_RF_AL7230B_SUPPORT=0
endif

#### AP Broadcast Handling ####
ifeq ($(ZDCONF_DRV_FORWARD), y)
EXTRA_CFLAGS += -DZDCONF_DRV_FORWARD=1
else
EXTRA_CFLAGS += -DZDCONF_DRV_FORWARD=0
endif

#### AP Client Support ####
ifeq ($(ZDCONF_APC), y)
EXTRA_CFLAGS += -DZDCONF_APC=1
else
EXTRA_CFLAGS += -DZDCONF_APC=0
endif

#### 802.11A Support ####
ifeq ($(ZDCONF_80211A_SUPPORT), y)
EXTRA_CFLAGS += -DZDCONF_80211A_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_80211A_SUPPORT=0
endif

ifeq ($(ZDCONF_EXTRA_FIX_RDC),y)
EXTRA_CFLAGS += -DZDCONF_R8610_FRAG_FIX=1
else
EXTRA_CFLAGS += -DZDCONF_R8610_FRAG_FIX=0
endif

ifeq ($(ZDCONF_DEFER_RX),y)
EXTRA_CFLAGS += -DZDCONF_DEFER_RX=1
else
EXTRA_CFLAGS += -DZDCONF_DEFER_RX=0
endif

ifeq ($(ZDCONF_TX_NOCOPY),y)
EXTRA_CFLAGS += -DZDCONF_TX_NOCOPY=1
else
EXTRA_CFLAGS += -DZDCONF_TX_NOCOPY=0
endif

ifeq ($(ZDCONF_DTIM_BC_FIX),y)
EXTRA_CFLAGS += -DZDCONF_DTIM_BC_FIX=1
else
EXTRA_CFLAGS += -DZDCONF_DTIM_BC_FIX=0
endif


ifeq ($(ZDCONF_WPS_SUPPORT),y)
EXTRA_CFLAGS += -DZDCONF_WPS_SUPPORT=1
else
EXTRA_CFLAGS += -DZDCONF_WPS_SUPPORT=0
endif


ifeq ($(ZDCONF_RATE_DEGRADE),y)
EXTRA_CFLAGS += -DZDCONF_RATE_DEGRADE=1
else
EXTRA_CFLAGS += -DZDCONF_RATE_DEGRADE=0
endif


ifeq ($(ZDCONF_FULL_REGTABLE),y)
EXTRA_CFLAGS += -DZDCONF_FULL_REGTABLE=1
else
EXTRA_CFLAGS += -DZDCONF_FULL_REGTABLE=0
endif
ifeq ($(ZD1211REV_B),1)
	EXTRA_CFLAGS += -DZD1211B
    obj-m := zd1211b.o
    ifeq ($(KERN_26), y)
        MODULE=zd1211b.ko
    else
        MODULE=zd1211b.o
    endif
endif
ifeq ($(ZD1211REV_B),0)
	EXTRA_CFLAGS += -DZD1211
    obj-m := zd1211.o
    ifeq ($(KERN_26), y)
        MODULE=zd1211.ko
    else
        MODULE=zd1211.o
    endif
endif

zd1211-objs := $(SRC_DIR)/zd1205.o \
$(SRC_DIR)/zdreq.o \
$(SRC_DIR)/zdasocsvc.o \
$(SRC_DIR)/zdauthreq.o \
$(SRC_DIR)/zdauthrsp.o \
$(SRC_DIR)/zdmmrx.o \
$(SRC_DIR)/zdshared.o \
$(SRC_DIR)/zdhci.o \
$(SRC_DIR)/zdglobal.o \
$(SRC_DIR)/zdencrypt.o \
$(SRC_DIR)/zdpmfilter.o \
$(SRC_DIR)/zdpsmon.o \
$(SRC_DIR)/zdsynch.o \
$(SRC_DIR)/zdbuf.o \
$(SRC_DIR)/zd1205_proc.o \
$(SRC_DIR)/zdhw.o \
$(SRC_DIR)/zddebug.o \
$(SRC_DIR)/zdmic.o \
$(SRC_DIR)/zddebug2.o \
$(SRC_DIR)/zdlpmgt.o \
$(SRC_DIR)/zdturbo_burst.o \
$(SRC_DIR)/zdusb.o  \
$(SRC_DIR)/zdmisc.o \
$(SRC_DIR)/zdregDomain.o \
$(SRC_DIR)/hpAntDiversity.o

zd1211-objs += $(SRC_DIR)/zd1211.o
zd1211b-objs = $(zd1211-objs)

ifeq ($(KERN_26), y)
all:
ifneq ($(KERNELRELEASE),)

else
ifndef ZD1211REV_B
		make both
else
		@echo -e $(KDIR)
		@echo -e $(PWD)
		@echo -e $(EXTRA_CFLAGS)
		@echo -e $(zd1211-objs)
		$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif

endif

else  #kernel 2.4

ifndef ZD1211REV_B
all:
	make both
else
all: $(obj-m)
endif

$(obj-m): $(zd1211-objs)
	$(LD) -static -r  $(zd1211-objs) -o $(obj-m)
	chmod -x $(obj-m)

%.o: %.c
	$(CC) -static $(EXTRA_CFLAGS) $(INCLUDES) $(DEFINES) $(DEBUG) -c $< -o $@                              
endif
    
both:
	make clean
	make ZD1211REV_B=0
	make ZD1211REV_B=0 install
	make clean
	make ZD1211REV_B=1
	make ZD1211REV_B=1 install

	
ifndef ZD1211REV_B
install: 
	@echo "'make' compile & install the driver"
	@echo "'make install' isn't required"
else
install: all
	mkdir -p $(MODPATH)/net
	cp $(MODULE) $(MODPATH)/net
	depmod -a
endif

menuconfig:
	chmod a+x scripts/lxdialog/lxdialog
	/bin/sh scripts/Menuconfig

debug:
	gcc -o apdbg apdbg.c
	chmod +x apdbg
	cp ./apdbg /sbin/apdbg   
	make -C Menudbg
	mv Menudbg/menudbg .
	chmod +x menudbg
	cp ./menudbg /sbin
	gcc -DPKT_SEND_FUNCTION -o winevl_iface Winevl_iface/pkt_send.c Winevl_iface/winevl_bridge.c

clean:
	rm -rf .tmp_versions .*.cmd *.ko *.mod.c *.mod.o *.o $(SRC_DIR)/*.o  $(SRC_DIR)/.*.o.cmd menudbg apdbg winevl_iface


